@extends('layouts.console_header')

@section('title', '后台账号列表')

@section('resources')
    @parent
    <style>
        table{margin-top: 50px;}
        table tr td{width: 100px;height: 50px;}
    </style>
@endsection

@section('content')
<section class="user_list">
    <div style="border-bottom: 2px solid #9955c6;overflow: hidden;">
        <p class="fz_14 account_title fl" style="border: none;"><span style="color: #7f7f7f;">
        <a href="/console/index">首页</a>>用户后台管理></span><span class="co_violet">后台帐号列表</span></p>
        <a href="#"><p class="fr tc back_btn">导出</p></a>
        <a href="/console/admin/account/new?cityid={{$cityid}}"><p class="fr tc back_btn">+新增</p></a>
    </div>
    <table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>序号</th>
                <th>姓名</th>
                <th>帐号</th>
                <th>角色</th>
                <th>创建时间</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @foreach($lists as $list)
                <tr>
                @if(!isset($i))
                    <td>{{$i=1}}</td>
                @else
                    <td>{{++$i}}</td>
                @endif
                    <td>{{$list['realname']}}</td>
                    <td>{{$list['mobile']}}</td>
                    <td>{{$list['rolename']}}</td>
                    <td>{{date('Y-m-d H:i', strtotime($list['created_at']))}}</td>
                @if($list['status'] == '1')
                    <td>可用</td>
                @elseif($list['status'] == '2')
                    <td>离职</td>
                @else
                    <td>不可用</td>
                @endif
                    <td>
                @if($roleid==1)
                    <!-- 超级管理员-->
                    {{--@if($list['roleid'] !=1)--}}
                        <a style="color: #9955c6;" href="/console/admin/account/get?adminuserid={{$list['id']}}&cityid={{$cityid}}">修改</a> &nbsp;&nbsp;
                        @if($list['status'] == '1')
                                <a style="color: red;" href="#" onclick="update_account_status('{{$list['id']}}', '0')">禁用</a>
                        @elseif($list['status'] == '0')
                                <a style="color: red;" href="#" onclick="update_account_status('{{$list['id']}}', '1')">恢复</a>
                        @endif
                    {{--@endif--}}
                @elseif($roleid ==2)
                    <!-- 管理员-->
                    @if(($list['roleid']!=1) && ($list['roleid']!=2))
                        <a style="color: #9955c6;" href="/console/admin/account/get?adminuserid={{$list['id']}}&cityid={{$cityid}}">修改</a> &nbsp;&nbsp;
                        @if($list['status'] == '1')
                                <a style="color: red;" href="#" onclick="update_account_status('{{$list['id']}}', '0')">禁用</a>
                        @elseif($list['status'] == '0')
                                <a style="color: red;" href="#" onclick="update_account_status('{{$list['id']}}', '1')">恢复</a>
                        @endif
                    @endif
                @elseif($roleid == 4)
                    <!-- 代理商-->
                    @if($list['roleid']>10)
                        <a style="color: #9955c6;" href="/console/admin/account/get?adminuserid={{$list['id']}}&cityid={{$cityid}}">修改</a> &nbsp;&nbsp;
                        @if($list['status'] == '1')
                                <a style="color: red;" href="#" onclick="update_account_status('{{$list['id']}}', '0')">禁用</a>
                        @elseif($list['status'] == '0')
                                <a style="color: red;" href="#" onclick="update_account_status('{{$list['id']}}', '1')">恢复</a>
                        @endif
                    @endif
                @else
                    @if($list['status'] == '1')
                            <a style="color: red;" href="#" onclick="update_account_status('{{$list['id']}}', '0')">禁用</a>
                    @elseif($list['status'] == '0')
                            <a style="color: red;" href="#" onclick="update_account_status('{{$list['id']}}', '1')">恢复</a>
                    @endif
                @endif
                    </td>
                </tr>
            @endforeach
        </tbody>
    </table>
</section>
@endsection

@section('scriptResources')
    @parent
    <script>
        var cityid='{{$cityid}}';
        //禁用,或者恢复
        function update_account_status(id, status) {
            $.ajax({
                url : '/console/admin/account/status/edit',
                data:{
                    "cityid":cityid,
                    "status":status,
                    'accountid':id
                    },
                dataType:'json',
                type:'post',
                success:function(data){
                    if(data.status == 'success') {
                        alert(data.message);
                        window.location.reload();
                    } else {
                        alert(data.message);
                    }
                }
            });
        }

    </script>
@endsection